All Questions
54 questions
1vote
4answers
748views
Passing arrays as global variables instead of pointers in C
I'm required to write the Low-Level Requirements of a Software Component which shall perform signal processing over arrays of 200k elements of integers/floats which lives in the main memory of the ...
0votes
1answer
79views
Avoiding repeating code when assigning pointer addresses based on branch
I have the following code in C that reads data off a char array and makes decisions on what variables should some pointers point to. char preset1[20]; char preset1Name[20]; int preset1Temp; int ...
0votes
1answer
111views
Is it safe to make training data and labels as global variables in C?
I'm trying to make this function called walk in C. The idea is that the function takes as parameters a point in space (represented by an array), a function (pointer), and a step size / learning rate ...
0votes
1answer
402views
Implement Dependency Inversion in C with UML diagram
As per Robert C. Martin in Clean Architecture, he gives a simple UML diagram to illustrate Dependency Inversion. To put it simply, HL1 initially referred to ML1 without interface to invoke F() ...
0votes
1answer
122views
What design pattern (if so) did I apply? How can I further improve it?
Suppose I have a program.c that needs element_123 to do some operations, and element_123 can be accessed by including agent.h /*program.c*/ #include "agent.h" uint32_t element_123 = 0; ...
-2votes
2answers
182views
What is the correct use of -> operator when working with pointers?
I'm pretty new with C so I have encountered many doubts with pointers. I've already search a lot about this but there are some things that still are not clear for me, and I also think this will help ...
5votes
1answer
7kviews
Why do we need to specify the type of data a pointer will hold, if all pointers are the same [duplicate]
Why do we need to specify the type of the data whose address, a pointer will hold, if all pointers are the same. Since all pointers store addresses. Also, the amount of space a pointer will require in ...
-1votes
1answer
182views
Pointers and Values in C
I do a lot of work in various languages, most of which are scripting languages such as JavaScript, Shell Scripting, PHP and so on. But I do also work a lot with Java, which is closer to a more "real" ...
1vote
2answers
315views
Setting a pointer to NULL on failure?
I've been modifying some code written by a previous employee and came across a function with the following signature: BOOL WINAPI PrependPadding( _In_ SIZE_T cbPadding, _In_ SIZE_T cbRow, ...
26votes
3answers
8kviews
Why does a long int take 12 bytes on some machines?
I noticed something strange after compiling this code on my machine: #include <stdio.h> int main() { printf("Hello, World!\n"); int a,b,c,d; int e,f,g; long int h; ...
1vote
2answers
2kviews
How to avoid lots of ugly pointer casting when using a container in C?
Let's say I have a container in C, for example something similar to C++' std::deque: struct deque { // blah }; struct deque* deque_create(size_t element_size, size_t init_deq_size); void* ...
4votes
1answer
2kviews
Should opaque pointers be pointers or types?
A common way to implement "PIMPL" in C is to do this: typedef struct _Opaque Opaque; Opaque* createOpaque(); void doSomething(Opaque *opaque); Or: typedef struct _Opaque* Opaque; Opaque ...
5votes
2answers
4kviews
Type safety - GO vs C pointers
C is a static-typed language that is not type-safe, because pointers(void *y) let you do pretty much anything you like, even things that will crash your program. GO is also a static typed language ...
2votes
2answers
5kviews
Struct "prototypes" in (plain)C?
As the title says, can it be done? struct Room{ char *type; //Lecture hall, laboratory, etc. char *name; int *capacity; //How may people it can hold struct Building *building; }; ...
9votes
6answers
2kviews
In C, is * an operator, or part of a type in a declaration?
In C, * is called the indirection operator or the dereference operator. I understand how it works when it is used in a statement. It makes sense to write *p or * p, considering that it is a unary ...